import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Inject,
  UseInterceptors,
  UseGuards,
} from '@nestjs/common';
import { YuicService } from './yuic.service';
import { CreateYuicDto } from './dto/create-yuic.dto';
import { UpdateYuicDto } from './dto/update-yuic.dto';
import { YuicInterceptor } from './yuic.interceptor';
import { YuicGuard } from './yuic.guard';
import { YuicDecorator } from './yuic.decorator';
import { ApiTags, ApiOperation, ApiProperty } from '@nestjs/swagger';
class yuicDto {
  @ApiProperty()
  name: string;
  @ApiProperty()
  id: number;
}
@ApiTags('yuic接口')
@Controller('yuic')
export class YuicController {
  constructor(
    private readonly yuicService: YuicService,
    @Inject('yuiyi') private readonly yuiyicService: YuicService,
    @Inject('yuiyivalue') private readonly yuiyicServicevalue: string[],
    @Inject('FactoryProvider') private readonly yuiyicFactoryProvider: any,
    @Inject('FactoryProviderPromise')
    private readonly FactoryProviderPromise: any,
  ) {}

  @Post()
  create(@Body() createYuicDto: yuicDto) {
    console.log(createYuicDto);
    return 'aaa';
  }

  @ApiOperation({
    tags: ['haha', 'wode'],
    summary: '这是summary',
    description: '这是description',
    externalDocs: {
      description: 'externalDocs的description',
      url: 'externalDocs的url',
    },
    operationId: 'operationId',
  })
  @UseInterceptors(YuicInterceptor)
  // @UseGuards(new YuicGuard(10))
  @Get('test')
  findAlls() {
    // return this.yuiyicService.findAll();
    // return this.yuiyicServicevalue;
    // return this.yuiyicFactoryProvider;
    return this.FactoryProviderPromise;
  }

  @UseInterceptors(YuicInterceptor)
  @UseGuards(new YuicGuard(10))
  @Get()
  findAll(@YuicDecorator('level') level: string) {
    // return this.yuiyicService.findAll();
    // return this.yuiyicServicevalue;
    // return this.yuiyicFactoryProvider;
    console.log('findAll', level);
    return this.FactoryProviderPromise;
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.yuicService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateYuicDto: UpdateYuicDto) {
    return this.yuicService.update(+id, updateYuicDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.yuicService.remove(+id);
  }
}
